
#import "myAppDelegate.h"
#import "MyView.h"

@implementation myAppDelegate

@synthesize window;
@synthesize contentView;

- (void)applicationWillResignActive:(UIApplication *)application
{ // interrupt begin
	MyView* pView = (MyView*)self.contentView;
	[pView SetInterrupt:true];// avoid pressed lock button, not play music before come back
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{ // interrupt back
	MyView* pView = (MyView*)self.contentView;
	[pView SetInterrupt:false];	
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {	
	
/*	
	IONotificationPortRef notificationPort;
	io_object_t notifier;
	root_port = IORegisterForSystemPower(self, &notificationPort, powerCallback, &notifier);
	CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopCommonModes); 
*/	
	
	// make the application disable the auto lock.
	[UIApplication sharedApplication].idleTimerDisabled = YES;
	
	CGRect rect = [[UIScreen mainScreen] bounds];
	
	// Create window
	self.window = [[UIWindow alloc] initWithFrame:rect];
    
	// Set up content view
	self.contentView = [[MyView alloc] initWithFrame:[window bounds]];
	[window addSubview:contentView];
    
	[(MyView*)contentView OnTimer];
	
	// Show window
	[window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
	
	[UIApplication sharedApplication].idleTimerDisabled = NO;
	
	MyView * pView = (MyView *)self.contentView;
	[pView onExit];
	[self dealloc];
}

- (void)dealloc {
	[contentView release];
	[window release];
	[super dealloc];
}

/*
- (void)powerMessageReceived:(natural_t)messageType withArgument:(void*)argument
{
	switch (messageType) {
		case kIOMessageSystemWillSleep:
			IOAllowPowerChange(root_port, (long)argument); 
			break;
		case kIOMessageCanSystemSleep:
			//if([self wifiKeepAliveIsSet]) {
			IOCancelPowerChange(root_port, (long)argument);
			//}
			break; 
		case kIOMessageSystemHasPoweredOn:
			break;
	}
}
 */

@end